import { env } from '@/config.js';
let baseURL = env.serviceDesk.qmsBaseURL;

const RequestService = (method = 'GET', path, params) => {
    if (env.hasChangEnv) {
        let qmsServiceBaseURL = env.qmsServiceBaseURL
        let apiEnv = uni.getStorageSync('apiEnv');
        if (apiEnv) {
            baseURL = qmsServiceBaseURL[apiEnv]
        } else {
            baseURL = qmsServiceBaseURL[env.env]
        }
    }
    uni.showLoading({
        title: '加载中',
        mask: true
    });
    console.log(`${baseURL}${path}`, params, 'qms', env.env)
    return new Promise((resolve, reject) => {
        uni.request({
            url: `${baseURL}${path}`,
            method,
            data: {
                ...params
            },
            success: (res) => {
                if (res.statusCode == 200) {
                    resolve(res.data)
                } else {
                    uni.showToast({
                        title: '业务繁忙稍后再试',
                        icon: 'none'
                    })
                    reject('业务繁忙稍后再试')
                }
                console.log('qms', res)
            },
            fail: (err) => {
                uni.showToast({
                    title: '业务繁忙稍后再试',
                    icon: 'none'
                })
                reject(err);
            },
            complete() {
                uni.hideLoading();
            }
        })
    })
}

export function qmsQueryByUserCode(params) {
    return RequestService("GET", "/api/open/queryByUserCode", params)
}

export function qmsOneAppLogin(params) {
    return RequestService("GET", "/oneAppLogin", params)
}